
from DailyBase import *
from AGDefines import *
import logging
import random


logger = logging.getLogger(__name__)


class HuanJing(DailyBase):

    def __init__(self, enum):
        self.RCName = __name__
        self.LogHeader = self.RCName +str(enum.port)
        self.enum = enum
        self.started = False
        self.loadPrivateActions(self.areaDict, HuanJingActions)
        logger.info("{} has {} actions".format(self.LogHeader, len(self.areaDict)))
        self.DaAn = [(205, 295, "HJDaAn1"), (400, 295, "HJDaAn2"), (205, 370, "HJDaAn3"), (400, 370, "HJDaAn4")]



    def KaiShi(self):
        self.begin(isDaily=False)

    def process_private(self, img = None, data = None):

        if self.areaDict['TouZhi'].detect(img, self.enum) < 10:
            self.enum.click(self.areaDict['TouZhi'].click)
            self.waitTime = 2
        elif self.areaDict['HJDaTi'].detect(img, self.enum) < 10:
            self.waitTime = 2
            self.HJAnswer(img)


    def HJAnswer(self, img):
        idx = random.randint(0, 3)
        self.enum.click(self.DaAn[idx])

